package DBConnection;

import Bank.MD5Utils;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Objects;

/**
 * Created by Дмитрий on 28.02.2015.
 *
 */
public class DBObject {

    private BigInteger ID;
    private BigInteger type;
    private String name;
    private BigInteger reference;
    private BigInteger parent_id;
    private HashMap<BigInteger, Object> attributes;

    public DBObject(BigInteger ID, BigInteger type, String name, BigInteger reference, BigInteger parent_id, HashMap<BigInteger, Object> attributes) {
        this.ID = ID;
        this.type = type;
        this.name = name;
        this.reference = reference;
        this.parent_id = parent_id;
        this.attributes = attributes;
    }

    public BigInteger getID() {
        return ID;
    }

    public BigInteger getType() {
        return type;
    }

    public HashMap<BigInteger, Object> getAttributes() {
        return attributes;
    }

    public String getName() {
        return name;
    }

    public BigInteger getReference() {
        return reference;
    }

    public BigInteger getParent_id() {
        return parent_id;
    }

    public void setName(String name) {
        this.name = name;
    }

    //возвращает атрибут из HashMap по ID
    public Object getAttributeById(BigInteger attrId){
        if (attributes.containsKey(attrId))
            return attributes.get(attrId);
        return "Attribute dot`t exist";
    }

    public void setAttribute(BigInteger id, Object attr){
        if (Objects.equals(id, DBAPI.ATTR_PASSWORD)) {
            attr = MD5Utils.md5Custom((String)attr);
        }
        attributes.put(id, attr);
    }

}